package cn.tedu.xmfhlittlebird.controller;

import cn.tedu.xmfhlittlebird.pojo.dto.CouponIssueAddNewDTO;
import cn.tedu.xmfhlittlebird.pojo.dto.CouponIssueUpdateDTO;
import cn.tedu.xmfhlittlebird.pojo.vo.StoreCouponIssueListItemVO;
import cn.tedu.xmfhlittlebird.pojo.vo.StoreCouponIssueStandardVO;
import cn.tedu.xmfhlittlebird.service.ICouponIssueService;
import cn.tedu.xmfhlittlebird.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coupons/issue")
@Slf4j
@Api(tags = "优惠券领取信息管理模块")
@Validated
public class CouponIssueController {
    @Autowired
    private ICouponIssueService couponIssueService;

    @ApiOperation("添加优惠券领取信息")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated CouponIssueAddNewDTO couponIssueAddNewDTO) {
        log.debug("开始处理【添加优惠券领取信息】的请求：{}", couponIssueAddNewDTO);
       couponIssueService.addNew(couponIssueAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除优惠券领取信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "优惠券id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除优惠券领取信息】的请求：id={}", id);
        couponIssueService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改优惠券领取信息详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "优惠券id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, CouponIssueUpdateDTO couponIssueUpdateDTO) {
        log.debug("开始处理【修改优惠券领取详情】的请求：id={}, couponIssueUpdateDTO={}", id, couponIssueUpdateDTO);
        couponIssueService.updateById(id, couponIssueUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("设置无限优惠券")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "优惠券领取信息id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setPermanent(@PathVariable Long id) {
        log.debug("开始处理【设置无限优惠券】的请求：id={}", id);
        couponIssueService.setPermanent(id);
        return JsonResult.ok();
    }

    @ApiOperation("设置有限优惠券")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "优惠券领取信息id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setTemporary(@PathVariable Long id) {
        log.debug("开始处理【禁用优惠券】的请求：id={}", id);
        couponIssueService.setTemporary(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询优惠券详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "优惠券领取信息id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<StoreCouponIssueStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询优惠券领取信息详情】的请求：id={}", id);
        StoreCouponIssueStandardVO couponIssue = couponIssueService.getStandardById(id);
        return JsonResult.ok(couponIssue);
    }

    @ApiOperation("查询优惠券领取列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<StoreCouponIssueListItemVO>> list() {
        log.debug("开始处理【查询优惠券领取列表】的请求……");
        List<StoreCouponIssueListItemVO> list = couponIssueService.list();
        return JsonResult.ok(list);
    }
    

}
